<template>
  <div>
    <div class="user-base-info" v-if="userinfo">
      <img :src="userinfo.header_img" alt="" />
      <div class="nickname">{{ userinfo.wechat_name }}</div>
      <div class="value">
        <b>{{ userinfo.user_coupon }}</b
        ><span>优惠券</span>
      </div>
      <div class="value">
        <b>{{ userinfo.good_collection }}</b
        ><span>我的收藏</span>
      </div>
      <div class="value">
        <b>{{ userinfo.shop_collection }}</b
        ><span>店铺关注</span>
      </div>
    </div>
    <div class="order-info">
      <div class="item">待下单<span>12</span></div>
      <div class="item">待下单<span>31</span></div>
      <div class="item">待下单<span>122</span></div>
      <div class="item">待下单<span>0</span></div>
    </div>
    <div class="cont-title">
      <b>我的订单</b
      ><span @click="$router.push({ path: '/user/order' })"
        >查看全部订单<icon name="iconxiangyou" size="12"
      /></span>
    </div>
    <div class="order-list">
      <OrderItem
        :order="item"
        v-for="(item, index) in orderList"
        :key="index"
      />
    </div>
    <YouLike1 />
  </div>
</template>

<script>
import api from "@/api";
import { mapState } from "vuex";
import OrderItem from "@/components/OrderItem/OrderItem.vue";
import YouLike1 from "@/components/YouLike/YouLike1";
export default {
  name: "UserCenter",
  components: { OrderItem, YouLike1 },
  computed: {
    ...mapState("user", ["userinfo"]),
  },
  data() {
    return {
      usercenter_info: {},
      orderList: [],
      order_query: {
        current: 1,
        length: 2,
      },
    };
  },
  created() {
    this.getUserInfo();
    this.getOrderList();
  },
  methods: {
    async getUserInfo() {
      let userinfo = await api.USERS_CENTER();
      this.$store.commit("user/set", userinfo);
    },
    async getOrderList() {
      let result = await api.ORDER_LIST(this.order_query);
      this.orderList = result.data;
    },
  },
};
</script>

<style lang="scss" scoped>
.user-base-info {
  height: 108px;
  background: #f3f5f9;
  border-radius: 5px;
  display: flex;
  align-items: center;
  img {
    width: 69px;
    height: 69px;
    margin: 0 20px 0 40px;
    border: 1px solid #c7c7c7;
    border-radius: 50%;
  }
  .nickname {
    font-size: 16px;
    font-weight: 600;
    color: #333333;
    flex: 1;
  }
  .value {
    min-width: 60px;
    display: flex;
    flex-direction: column;
    margin: 0 73px;
    align-items: center;
    b {
      font-size: 26px;
      font-weight: 400;
      color: #333333;
      line-height: 37px;
    }
    span {
      margin-top: 12px;
      font-size: 16px;
      font-weight: 400;
      color: #666666;
      line-height: 15px;
    }
  }
}
.order-info {
  display: flex;
  margin-bottom: 20px;
  .item {
    flex: 1;
    height: 36px;
    border: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 400;
    color: #666666;
    span {
      padding-left: 12px;
      font-weight: 600;
      color: #d52c1a;
    }
  }
}
.cont-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  b {
    font-size: 20px;
    font-weight: 600;
    color: #333333;
  }
  span {
    font-size: 16px;
    font-weight: 400;
    color: #333333;
    i {
      position: relative;
      top: -1px;
      padding-left: 6px;
    }
  }
}
.order-item {
  margin: 14px 0 20px;
  .order-title {
    height: 36px;
    padding: 0 20px;
    background: #f3f5f9;
    border: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    .time {
      font-size: 16px;
      color: #666666;
      margin-right: 16px;
    }
    .num {
      font-size: 16px;
      color: #333333;
      margin-right: 20px;
    }
    img {
      width: 28px;
      height: 28px;
      border-radius: 5px;
      margin-right: 12px;
    }
    .name {
      font-size: 16px;
      font-weight: 600;
      color: #333333;
    }
  }
  .order-info {
    .goods {
      width: 480px;
      height: 120px;
      box-sizing: border-box;
      border: 1px solid #dedede;
      display: flex;
      padding: 20px;
      img {
        width: 78px;
        height: 78px;
        border-radius: 5px;
        margin-right: 12px;
      }
      .text {
        display: flex;
        width: 200px;
        margin-right: 40px;
        flex-direction: column;
        justify-content: space-between;
        .title {
          font-size: 14px;
          color: #333333;
          line-height: 20px;
        }
        .spec {
          font-size: 14px;
          color: #666666;
          line-height: 20px;
        }
      }
      .price {
        display: flex;
        flex-direction: column;
        font-size: 14px;
        font-weight: 600;
        color: #333333;
        line-height: 20px;
        margin-right: 20px;
        s {
          color: #999999;
        }
      }
      .number {
        font-size: 14px;
        font-weight: 600;
        color: #333333;
        line-height: 20px;
      }
    }
    .money {
      width: 182px;
      box-sizing: border-box;
      height: 120px;
      border: 1px solid #dedede;
      border-width: 1px 1px 1px 0;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      font-size: 14px;
      color: #666666;
      line-height: 20px;
      b {
        font-size: 20px;
        font-weight: 600;
        color: #333333;
        line-height: 28px;
        margin-bottom: 12px;
      }
    }
    .status {
      width: 140px;
      box-sizing: border-box;
      height: 120px;
      border: 1px solid #dedede;
      border-width: 1px 1px 1px 0;
      display: flex;
      padding: 20px;
      align-items: center;
      flex-direction: column;
      font-size: 16px;
      color: #333333;
      line-height: 22px;
      span {
        margin-bottom: 8px;
      }
      & > span:last-child {
        margin-bottom: 0;
      }
    }
    .action {
      width: 160px;
      box-sizing: border-box;
      height: 120px;
      border: 1px solid #dedede;
      border-width: 1px 1px 1px 0;
      display: flex;
      padding: 20px;
      align-items: center;
      flex-direction: column;
      font-size: 16px;
      color: #666666;
      line-height: 22px;
      span {
        margin-bottom: 8px;
      }
      & > span:last-child {
        margin-bottom: 0;
      }
    }
  }
}
.goods-list {
  font-size: 0;
  margin-top: 20px;
  ::v-deep .goods-item {
    border-color: #f0f0f0;
    margin-left: 21px;
  }
  & > div:nth-child(4n + 1) {
    margin-left: 0;
  }
}
</style>
